package com.sun.controller.admin;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.pojo.Orders;
import com.sun.pojo.Room;
import com.sun.service.OrdersService;
import com.sun.service.RoomService;
import com.sun.utils.DataGridViewResult;
import com.sun.utils.SystemConstant;
import com.sun.vo.OrdersVo;
import com.sun.vo.RoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/admin/orders")
public class OrdersAdminController {

    @Autowired
    private OrdersService ordersService;

    @RequestMapping("/list")
    public DataGridViewResult list(OrdersVo ordersVo){
        return ordersService.list(ordersVo);
    }

    @RequestMapping("/confirmOrders")
    public String confirmOrders(int id){
        HashMap<String, Object> map = new HashMap<String, Object>();

        int i=ordersService.confirmOrders(id);
        if(i>0){
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"确认成功!");
        }else{
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"确认失败!");
        }
        return JSON.toJSONString(map);
    }

    @RequestMapping("/batchConfirmOrders")
    public String batchConfirmOrders(String ids){
        HashMap<String, Object> map = new HashMap<String, Object>();

        int i=ordersService.batchConfirmOrders(ids);
        if(i>0){
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"批量确认成功!");
        }else{
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"批量确认失败!");
        }
        return JSON.toJSONString(map);
    }
}
